package com.lpf.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NioTest08 {

    public static void main(String arg[]) throws Exception {

        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\LIUPEIFENG\\IdeaProjects\\Netty-Learning\\netty-zhanglong\\src\\main\\java\\com\\lpf\\nio\\text\\NioTest08_input.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\LIUPEIFENG\\IdeaProjects\\Netty-Learning\\netty-zhanglong\\src\\main\\java\\com\\lpf\\nio\\text\\NioTest08_output.txt");

        FileChannel inputChannel = fileInputStream.getChannel();
        FileChannel outputChannel = fileOutputStream.getChannel();

        ByteBuffer bb = ByteBuffer.allocateDirect(512);

        while (true) {
            bb.clear();
            int read = inputChannel.read(bb);
            System.out.println(read);
            if (-1 == read) {
                break;
            }
            bb.flip();
            outputChannel.write(bb);
        }

        fileInputStream.close();
        fileOutputStream.close();
    }
}
